package com.jy.admin.rest;


import com.fqgj.common.utils.StringUtils;
import com.fqgj.exception.common.ApplicationException;
import com.jy.admin.annotations.AdminSignIgnore;
import com.jy.admin.db.dao.AgentDao;
import com.jy.admin.db.dao.CeAgentAccountDao;
import com.jy.admin.db.dao.CeMerchantDao;
import com.jy.admin.db.dao.RewardConfigDao;
import com.jy.admin.db.entity.RewardConfigEntity;
import com.jy.admin.services.cashPocket.vo.RewardRequest;
import com.jy.bo.common.conf.api.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/agent")
public class AgentController {
    private final static Logger LOGGER = LoggerFactory.getLogger(AgentController.class);

    @Autowired
    CeAgentAccountDao ceAgentAccountDao;

    @Autowired
    CeMerchantDao ceMerchantDao;

    @Autowired
    AgentDao agentDao;


    @AdminSignIgnore
    @RequestMapping("/query")
    public ApiResponse queryAgentByOrderNo(String merchantCode,String date,String orderNo,String mobile) {
        if (StringUtils.isEmpty(merchantCode)){
            return new ApiResponse<>(400,"请选择商户");
        }
        if (StringUtils.isEmpty(date)){
            return new ApiResponse<>(400,"请选择日期");
        }
        if (StringUtils.isEmpty(orderNo) && StringUtils.isEmpty(mobile)){
            return new ApiResponse<>(400,"请输入要查询的订单号或手机号");
        }
        if (StringUtils.isNotEmpty(orderNo)){
            String stuffCode = agentDao.queryAgentByOrderNo(merchantCode, date, orderNo);
            if (StringUtils.isEmpty(stuffCode)){
                return new ApiResponse<>(400,"无，请检查订单号是否正确");
            }
            return new ApiResponse<>(stuffCode);
        }
        if (StringUtils.isNotEmpty(mobile)){
            String stuffCode = agentDao.queryAgentByMobile(merchantCode, date, mobile);
            if (StringUtils.isEmpty(stuffCode)){
                return new ApiResponse<>(400,"无，请检查手机号是否正确");
            }
            return new ApiResponse<>(stuffCode);
        }
        return new ApiResponse<>("");
    }

    @AdminSignIgnore
    @RequestMapping("/query/whatsapp")
    public ApiResponse queryAgentByWhatsApp(String date,String whatsApp) {

        if (StringUtils.isEmpty(date)){
            return new ApiResponse<>(400,"请选择日期");
        }
        if (StringUtils.isEmpty(whatsApp)){
            return new ApiResponse<>(400,"请输入WhatsApp");
        }
        String stuffCode = agentDao.queryAgentByWhatsApp( date, whatsApp);
        if (StringUtils.isEmpty(stuffCode)){
            return new ApiResponse<>(400,"未查到该WhatsAp");
        }
        return new ApiResponse<>(stuffCode);
    }


}
